package com.zxc.csms.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SecurityTool {

	/**
	 * 使用MD5加密密码
	 * @param password
	 * @param key
	 * @return
	 * @throws NoSuchAlgorithmException
	 */
	public static String encryptPasswordWithMD5(String password, String key)
			throws NoSuchAlgorithmException {
		return getMD5Password(getMD5Password(password) + key);
	}
	
	private static String getMD5Password(String source)
			throws NoSuchAlgorithmException {
		MessageDigest messageDigest = MessageDigest.getInstance("MD5");
		messageDigest.update(source.getBytes());
		StringBuilder sb = new StringBuilder();
		for (byte b : messageDigest.digest()) {
			sb.append(String.format("%X", b));
		}
		return sb.toString();
	}
}
